<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<%-- <%@include file="edit.jsp"%> --%>
<html>
<head>
<script type="text/javascript">
	formatterDate = function (date) {
		var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
		var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0"
		+ (date.getMonth() + 1);
		var hor = date.getHours();
		var min = date.getMinutes();
		var sec = date.getSeconds();
		return date.getFullYear() + '-' + month + '-' + day+" "+hor+":"+min+":"+sec;
	};

	var startDt = formatterDate(new Date('${item.startDt}'));
	var endDt = formatterDate(new Date('${item.endDt}'));
	$(function() {
		$('#startDt').datetimebox('setValue',  startDt);
		$('#endDt').datetimebox('setValue', endDt);
		
		$('#enabled').radiobox({name:'entity.enabled',value:true,data:[[true,'有效'],[false,'无效']]});
		$('#toolbar').toolbar({buttons:[
			{name:'save',iconCls:'icon-save',text:'保存'}
	  	],handler:handler});
		$('#article_datagrid').datagrid({
			pagination:true,
			singleSelect:true,
			rownumbers:false,
			striped:true,
			fit:true,
			fitColumns:true,
			toorbar:'#article_toolbar',
			onSelect:setSelect,
			columns:[[
				{field:'id',title:'id'},
				{field:'articleTitle',title:'文章标题'},
	    		{field:'userName',title:'作者'},
	    		{field:'articleType',title:'类型',formatter:function(v,r,i){
	    			var type ="";
	    			if(r.articleType == "1"){type ="文章"}else if(r.articleType == "3"){type ="音频"}else if(r.articleType == "5"){type="视频"}else if(r.articleType == "7"){type="话题pk"}
	    			return type;
	    		}},
	    		{field:'markPublish',title:'发布标记',formatter:function(v,r,i){
	    			var publish='私密';
	    			if(r.markPublish){
	    				publish='公开';
	    			}
	    			return publish;
	    		}},
	    		{field:'countView',title:'浏览量'},
	    		{field:'countPraise',title:'点赞量'},
	    		{field:'countShare',title:'分享量'},
	    		{field:'countCollect',title:'收藏量'},
	    		{field:'markAudit',title:'审核标记',formatter:function(v,r,i){
	    			var audit='未审核';
	    			if(r.markAudit == '3'){
	    				audit='审核未通过';
	    			}else if(r.markAudit == '5'){
	    				audit='审核通过';
	    			}
	    			return audit;
	    		}},
	    		{field:'categoryId',title:'投稿',formatter:function(v,r,i){
	    			var category='未投稿';
	    			if(r.categoryId > 0){
	    				category='已投稿';
	    			}
	    			return category;
	    		}},
	    		{field:'enabled',title:'是否可用',formatter:function(v,r,i){
	    			var enab = '否';
	    			if(r.enabled){
	    				enab = '是'
	    			}
	    			return enab;
	    		}},
	    		{field:'createdDt',title:'创建时间'}
			]],
			view: detailview,
		    detailFormatter: function(rowIndex, rowData){
		        return '<table><tr>' +
		                '<td rowspan=2 style="border:0,height:50px;">'+rowData.articleContent+'</td>' +
		                '</tr></table>';
		    }
		 });
	
	});
	function handler() {
		switch(this.name) {
			case 'save': toSave();break;
		}
	}
	function toSave(){
		var isValid = $('#dataform').form('enableValidation').form('validate');
		var tip = $("#td_article_showTip").html("");
		var link = $("#entity_link").val();
		
		if(link.length<1){
			var div_tip = '<span style="color: red;">请添加广告链接</span>';
			tip.append(div_tip);
			isValid = isValid && false;
			return;
		}
		var imgurl = $("#imgurl").val();
		if(imgurl.length<1){
			var div_tip = '<span style="color: red;">请上传封面图片</span>';
			tip.append(div_tip);
			isValid = isValid && false;
			return;
		} 
		
		if(isValid){
			$.messager.progress({title:'系统提示',text:'数据处理中，请耐心等待...'});
			$.submit('#dataform',function(r) {
				$.messager.progress('close');
				if(r.code<0) return $alert(r.msg);
				top.$prompt('保存成功');
				top.$window.close(window,1,null);
			});
		}
	}
	
	function toDeploy(){
		showUpload({title:'上传封面'
			,options:{
				filters:{
					mime_types: [{title : "封面图片", extensions : "jpg,png"}]
				},
				multi_selection: false ,
				 init:{
					 FileUploaded:function(uploader,file,responseObject){
						 var response = responseObject.response;
						 var json = eval('(' + response + ')');
						 var data = json.data;
						 var path = data.fileUrl;
						 $("#imgurl").val(path);
						 showImg(path);
					 }
				},
				complete:function(){
					top.$ok('上传成功');
				}
			}
		});
	}
	function showImg(path){
		$("#img_show").attr("src",path);
	}
	function searchByitem(){
		var searchItem = {};
		searchItem.articleTitle = $("#article_title").textbox("getValue");
		/* searchItem.userName = $("#article_user").textbox("getValue"); */
		searchItem.articleType = $("#article_type").combobox("getValue");
		$('#article_datagrid').datagrid({ queryParams: searchItem,url:"/article/info/searchByUserAndTitleAndType"});   //点击搜索
	}
	function setSelect(index,row){
		var link = "id:"+row.id+"  作者:"+row.userName+"  标题:"+row.articleTitle;
		$("#link_show").textbox('setValue', link);
		$("#description").textbox('setValue', link);
		$("#entity_link").val(row.id);
	}
	
</script>
</head>
<body>
	<div id="toolbar" class="toolbar" ></div>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center',border:false" style="height:300px;">
			<form id="dataform" action="edit" method="post">
				<input type="hidden" name="entity.id" value="${item.id }">
				<input type="hidden" name="entity.enabled" value="${item.enabled}">
				<input type="hidden" name="entity.targetplace" value="1">
				<table cellpadding="5" style="width:100%;">
					<tr>
						<td style="width:20%;">广告标题:</td>
						<td style="width:80%;">
							<input class="easyui-textbox" value="${item.title }" name="entity.title" data-options="required:true"/>
						</td>
					</tr>
					<tr class="">
						<td>广告类型:</td>
						<td>
							<select class="easyui-combobox" name="entity.type">
								<%-- <option value="1" ${item.type==1?'selected':''}>栏目</option> --%>
								<option value="3" ${item.type==3?'selected':''}>内容</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>开始时间:</td>
						<td>
							<input class="easyui-datetimebox" id="startDt"  name="entity.startDt">
						</td>
					</tr>
					<tr>
						<td>结束时间:</td>
						<td>
							<input class="easyui-datetimebox" id="endDt"  name="entity.endDt">
						</td>
					</tr>
					<tr>
						<td>广告图片:</td>
						<td>
							<input type="button" value="上传" onclick="toDeploy()">
						</td>
					</tr>
					<tr>
						<td></td>
						<td >
							<input id="imgurl" name="entity.imgurl" type="hidden" value="${item.imgurl}">
							<img id="img_show" alt="广告图片" src="${item.imgurl }" style="width: 80px;height: 80px;">
						</td>
					</tr>
					<tr>
						<td>广告描述:</td>
						<td>
							<input id="description" class="easyui-textbox" name="entity.description" value="${item.description }" data-options="multiline:true" style="height:100px;width:100%;"/>
						</td>
					</tr>
					<tr class="form-tr">
						<th class="form-th">提示:</th>
						<td class="form-td" id="td_article_showTip">
						</td>
					</tr>
					<tr>
						<td  class="form-th">选择广告链接:</td>
						<td>
							<input type="hidden" id="entity_link" name="entity.link" required="required" value="${item.link }">
							<input id="link_show" class="easyui-textbox"  style="width: 100%" data-options="editable:false" />
						</td>
					</tr> 
				</table>
				<div>
					<table id="article_datagrid" class="easyui-datagrid" data-options="toolbar:'#article_toolbar'" style="width:100%;height:350px" ></table>
					<div id="article_toolbar">
						连接标题: <input class="easyui-textbox" style="width:200px" id="article_title">
						<!-- 作者: <input class="easyui-textbox" style="width:100px" id="article_user"> -->
						连接类型 ：
						<select class="easyui-combobox" panelHeight="auto" style="width:100px" id="article_type">
							<option value="1">图文</option>
							<option value="3">音频</option>
							<option value="5">视频</option>
							<option value="7">话题pk</option>
						</select>
						<a class="easyui-linkbutton" iconCls="icon-search" id="search_article" onclick="searchByitem();">搜索广告连接</a>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
</html>